// MyFamily - XML based genealogy program.
// Copyright (C) 2006  Doug Swisher
// See the file COPYING.txt for license details.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using NUnit.Framework;


namespace DataModel.Tests
{
    [TestFixture]
    public class GedComParsing
    {


        private GedComFile ReadGedCom(string fileName, int expectedWarnings)
        {
            FileInfo inputInfo = new FileInfo(Path.Combine("..\\..\\Tests\\Data\\", fileName));

            GedComReadResults gedResults = new GedComReadResults(inputInfo);

            GedComFile ged = GedComFile.Read(inputInfo, gedResults);

            foreach (string message in gedResults.Messages)
            {
                Console.WriteLine(message);
            }

            Assert.AreEqual(expectedWarnings, gedResults.WarningCount, "Warning count mismatch; see output for details.");

            return ged;
        }


        [Test]
        public void MinimalLinks()
        {
            GedComFile ged = ReadGedCom("Minimal.ged", 0);

            GedComNode head = null;
            GedComNode subm = null;
            foreach (GedComNode child in ged.Children)
            {
                switch (child.Tag)
                {
                    case "HEAD":
                        head = child;
                        break;

                    case "SUBM":
                        subm = child;
                        break;
                }
            }

            Assert.IsNotNull(head, "Head should not be null.");
            Assert.IsNotNull(subm, "Subm should not be null.");

            foreach (GedComNode child in head.Children)
            {
                if (child.Tag == "SUBM")
                {
                    Assert.AreEqual(subm, child.Destination, "HEAD.SUBM should point to SUBM");
                }
            }
        }


        [Test]
        public void BadLink()
        {
            GedComFile ged = ReadGedCom("BadLink.ged", 1);
        }

    }
}
